package cn.ztelovecly.springboot.framework.util.pdf;


/**
 *
 */
public class GeneratePdfRequest {
    /**
     * 命令行
     */
    private String commandLine;

    /**
     * Cookie名称
     */
    private String cookieName;

    /**
     * Cookie值
     */
    private String cookieValue;

    /**
     * 要生成PDF的URL
     */
    private String url;

    /**
     * 输出到的路径
     */
    private String outputPath;

    /**
     * 是否旋转页面。（横向输出）
     */
    private Layout layout = Layout.PORTRAIT;

    /**
     * 是否输出媒体信息
     */
    private Boolean printMedia;

    /**
     * 是否输出脚注
     */
    private Boolean printFooter;

    public GeneratePdfRequest() {
    }

    public GeneratePdfRequest(String commandLine, String cookieName, String cookieValue, String url, String outputPath) {
        this.commandLine = commandLine;
        this.cookieName = cookieName;
        this.cookieValue = cookieValue;
        this.url = url;
        this.outputPath = outputPath;
    }

    public GeneratePdfRequest(String commandLine, String cookieName, String cookieValue, String url, String outputPath, Layout layout) {
        this.commandLine = commandLine;
        this.cookieName = cookieName;
        this.cookieValue = cookieValue;
        this.url = url;
        this.outputPath = outputPath;
        if(layout != null) {
            this.layout = layout;
        }
    }

    public String getCommandLine() {
        return commandLine;
    }

    public void setCommandLine(String commandLine) {
        this.commandLine = commandLine;
    }

    public String getCookieName() {
        return cookieName;
    }

    public void setCookieName(String cookieName) {
        this.cookieName = cookieName;
    }

    public String getCookieValue() {
        return cookieValue;
    }

    public void setCookieValue(String cookieValue) {
        this.cookieValue = cookieValue;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getOutputPath() {
        return outputPath;
    }

    public void setOutputPath(String outputPath) {
        this.outputPath = outputPath;
    }

    public Layout getLayout() {
        return layout;
    }

    public void setLayout(Layout layout) {
        this.layout = layout;
    }

    public Boolean getPrintMedia() {
        return printMedia;
    }

    public void setPrintMedia(Boolean printMedia) {
        this.printMedia = printMedia;
    }

    public Boolean getPrintFooter() {
        return printFooter;
    }

    public void setPrintFooter(Boolean printFooter) {
        this.printFooter = printFooter;
    }

    public String getCommand() {
        StringBuilder cmd = new StringBuilder();
        cmd.append(commandLine)
                .append(" --cookie ").append(cookieName).append(" ")
                .append(cookieValue)
                .append(" --zoom 0.8 ")
                .append(" --no-stop-slow-scripts ")
                .append(" --load-error-handling ignore ");

        if(layout != null && layout == Layout.LANDSCAPE) {
            cmd.append(" --orientation Landscape ");
        }
        if(printMedia != null && !printMedia) {
            cmd.append(" --print-media-type ");
        }
        if(printFooter != null && printFooter) {
            cmd.append(" --footer-right [page]/[topage] ");
        }
        cmd.append(url).append(" /tmp").append(outputPath);

        return cmd.toString();
    }
}
